package com.hbjycl.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hbjycl.dao.BbsDao;
import com.hbjycl.entity.Bbs;
import com.hbjycl.entity.Comment;

@Repository
@Transactional
public class BbsDaoImpl extends BaseDaoImpl<Bbs, String>  implements BbsDao{
	@Override
	public Bbs getBbsBybbsname(String bbsname){
		String hql = "from Bbs bbs where bbs.bbsname = ?";
        return (Bbs) getSession().createQuery(hql).setParameter(0, bbsname).uniqueResult();
	}
	
	@Override
	public List<Bbs> getBbsByclicknum(){
	      String hql = "select bbs from Bbs bbs order by clicknum desc";
	      return getSession().createQuery(hql).list();
	}
	
	@Override
	public List<Bbs> getBbsBycommentnum(){
		  String hql = "select bbs from Bbs bbs order by commentnum desc";
	      return getSession().createQuery(hql).list();
	}
	public List<Bbs> getBbsBylasttime(){
		 String hql = "select bbs from Bbs bbs order by lasttime desc";
	      return getSession().createQuery(hql).list();
	}
	
	@Override
    public boolean isExistByBbsname(String bbsname)
    {
	    String hql = "from Bbs bbs where  bbs.bbsname  = ?";
        Bbs bbs = (Bbs) getSession().createQuery(hql).setParameter(0, bbsname)
                .uniqueResult();
        if (bbs != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    };
	
	    @Override
	    public List<Comment> getCommentList(String bbsname)
	    {
	       String hql = "select comment from Comment comment where comment.bbsname=? order by createDate desc";
		      return getSession().createQuery(hql).setParameter(0, bbsname).list();
	    }
}
